# 导入必要的库
import datetime
import logging

from twist_check import WireDetector

# 配置日志
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)

# 创建检测器实例（使用默认配置）
detector = WireDetector()

# 检测单张图像
image_path = "./files/002.jpg"
start_time = datetime.datetime.now()
start_time_str = start_time.strftime("%Y-%m-%d %H:%M:%S")

logger.info("开始时间: %s", start_time_str)
result = detector.detect_wire(image_path)

end_time = datetime.datetime.now()
end_time_str = end_time.strftime("%Y-%m-%d %H:%M:%S")
logger.info("结束时间: %s", end_time_str)

# 打印检测结果
print(f"是否检测到铁丝: {result['has_wire']}")
print(f"置信度分数: {result['confidence_score']:.2f}")
print(f"检测到的线条数: {result['line_count']}")
print(f"线条密度: {result['line_density']:.6f}")
